package bishi;

import java.util.Scanner;

public class Leetcode1312 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        System.out.println(minInsertions(s));
    }

    public static int minInsertions(String s) {
        int len = s.length();
        int[][] dp = new int[len][len];
        // base case：i == j 时 dp[i][j] = 0，单个字符本身就是回文
        // dp 数组已经全部初始化为 0，base case 已初始化
        for(int i = len-2;i>=0;i--){
            for(int j = i+1;j<len;j++){
                //根据s[i]和s[j]进行状态转移
                //如果s[i.....j]其中首和尾相等，那么就只需要求s[i+1....j-1]变换成回文串的最小次数
                if(s.charAt(i) == s.charAt(j)){
                    dp[i][j] = dp[i+1][j-1];
                }else{
                    dp[i][j] = Math.min(dp[i+1][j],dp[i][j-1]) +1;
                }
            }
        }
        return dp[0][len-1];
    }
}
